<template>
  <div class="wrapper">
    <BreakSpace label="车辆信息" :containerStyle="{ marginBottom: '10px' }" />
    <FormPanel ref="infoMain2" :list="formList2" :isSubmitBtn="false" />
    <BreakSpace label="变更信息" :containerStyle="{ marginBottom: '10px' }" />
    <FormPanel ref="infoMain3" :list="formList3" :isSubmitBtn="false" />
    <div>
      <FilterTable :columns="form" :isSubmitBtn="false" :isSelectColumn="false" ref="infoChanges" :onColumnsChange="(columns) => (this.form = form)" :dataSource="list2"
                   :onCellChange="cellChange">
      </FilterTable>
    </div>
    <div style="margin-top:10px">
      <FormPanel
        :cols="3"
        :list="form3"
        :isSubmitBtn="false"
        :labelWidth="85"
        ref="infoChanges1"
      />
    </div>
    <BaseDialog :visible.sync="visibleForm" :title="dialogTitle" destroyOnClose width="60vw"
                :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <FormPanel
        :cols="3"
        :list="form2"
        :isSubmitBtn="false"
        :labelWidth="85"
        ref="infoChanges2"
      />
      <div class="dialogBottmView">
        <el-button @click="closeDialog2()" >取 消</el-button>
        <el-button  type="primary"  @click="toExamine()">确 认</el-button>
      </div>
    </BaseDialog>
    <div v-show="!isDetailed">
      <BreakSpace label="审核记录" :containerStyle="{ marginBottom: '10px' }" />
      <FilterTable
        ref="table"
        :columns="columns"
        :dataSource="dataList1"
        :datakey="'records'"
        :isSelectColumn="false"
        columnsRef="notification_maintain_index_02"
        :onColumnsChange="columns => this.columns = columns"
      >
      </FilterTable>
    </div>
    <div class="dialogBottmView">
      <el-button @click="closeDialog()">关 闭</el-button>
      <el-button @click="saveDialog(false)" v-if="isDetailed" type="primary">通 过</el-button>
      <el-button @click="saveDialog(true)" v-if="isDetailed" type="primary">驳 回</el-button>
    </div>
  </div>
</template>
<script>
import moment from "moment";
import config from '@/assets/js/config';
import { dictionary } from '@/utils/dictMixin';
import { authority } from '@/utils/authMixin';
import {getMileagechange} from '@/api/customerRepair/vehicleOwnerManagement/vehicleMileageChange/index';
import {examineMileagechange} from "../../../../api/customerRepair/vehicleOwnerManagement/vehicleMileageChange";
export default {
  name: "newlyAdded",
  mixins: [authority, dictionary],
  props: {
    value: {
      type: Object,
      required: true
    },
    type: {
      type: String,
      required: true
    },
    row: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      formList2: this.createFormList2(),
      formList3: this.createFormList3(),
      form: this.createForm(),
      form2: this.createForm2(),
      columns: this.creatHeader(),
      dataList1:[],
      visibleForm: false,
      isDetailed:true,
      isEscalation:true,
      dialogTitle: '审核意见',
      list2:[],
      form3: this.createForm1(),
    };
  },
  mounted() {
    this.isDetailed = this.type == 'detail'?false:true;
    this.formList2.forEach(x=>{
      x.initialValue = this.row[x.fieldName];
    });
    this.formList3.forEach(x=>{
      if(x.fieldName === 'createdAt'){
        x.initialValue = moment(this.row[x.fieldName]).format('YYYY-MM-DD HH:mm:ss');
      }else{
        x.initialValue = this.row[x.fieldName];
      }
    });
    this.form3.forEach(x=>{
      x.initialValue = this.row[x.fieldName];
    });
    console.log("2423235",this.row)
    this.$refs.infoChanges.EXECUTE_INSERT(this.row.roList);
    this.$refs.table.EXECUTE_INSERT(this.row.exlogs);
  },
  methods:{
    createFormList2() {
      return [
        {type: 'INPUT', label: 'VIN', fieldName: 'vin', initialValue: '', disabled: true},
        { type: 'INPUT', label: '车牌号', fieldName: 'license',initialValue: '', disabled: true },
        { type: 'INPUT', label: '车系', fieldName: 'seriesName', initialValue: '', disabled: true },
        { type: 'INPUT', label: '车主名称', fieldName: 'ownerName',initialValue: '', disabled: true },
        { type: 'INPUT', label: '车主手机', fieldName: 'mobile',initialValue: '', disabled: true },
        { type: 'INPUT', label: '车型', fieldName: 'modelName',initialValue: '', disabled: true }
      ];
    },
    createFormList3() {
      return [
        {type: 'INPUT', label: '申请服务站', fieldName: 'dealerName', initialValue: '', disabled: true},
        {type: 'INPUT', label: '申请人', fieldName: 'createdBy', initialValue: '', disabled: true},
        {type: 'INPUT', label: '申请时间', fieldName: 'createdAt', initialValue: '', disabled: true},
        {type: 'INPUT', label: '车主车辆原里程', fieldName: 'oldMileage', initialValue: '', disabled: true},
        {type: 'INPUT', label: '变更里程', fieldName: 'newMileage', initialValue: '', disabled: true}
      ]
    },
    createForm() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          fixed: 'left',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {title: '工单', dataIndex: 'roNo', sorter: true},
        {title: '结算时间', dataIndex: 'balanceTime',dateFormat: 'yyyy-MM-dd HH:mm:ss', sorter: true},
        {title: '是否关联索赔', dataIndex: 'isRelationClaim', sorter: true},
        {title: '原工单里程', dataIndex: 'inMileage', sorter: true},
        {title: '变更里程', dataIndex: 'newMileage', sorter: true}
      ]
    },
    createForm1(){
      return [
        {
          type: 'TEXT_AREA',
          label: '变更原因说明',
          fieldName: 'remark',
          placeholder: '请输入',
          initialValue: '',
          selfCols: 3,
          rows:5,
          disabled: true
        },
        {
          type: 'UPLOAD_FILE',
          label: '附件上传',
          fieldName: 'file',
          placeholder: '选择文件...',
          initialValue: [],
          disabled: true,
          upload: {
            actionUrl: `${config.uploadUrl}/api/file/v1/file/upload`,
            fileTypes: ['pdf', 'jpg', 'png', 'rar', 'xls', 'xlsx','zip'],
            limit: 5,
            max: 1024 * 100,
            fileSize: 5
            //tipText: '（支持PDF、RAR、JPG、XLS、XLSX格式）'
          },
          selfCols: 4
        }
      ]
    },
    createForm2() {
      return[
        {
          type: 'TEXT_AREA',
          label: '审核意见',
          fieldName: 'checkOpinion',
          initialValue:'',
          selfCols: 2,
          rows:7
      }]
    },
    creatHeader() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {title: '审核时间', dataIndex: 'checkAt', dateFormat: 'yyyy-MM-dd HH:mm:ss', sorter: true},
        {title: '审核人', dataIndex: 'checkBy', sorter: true},
        {title: '审核结果', dataIndex: 'status', sorter: true,
          render: props => {
            return <span>{
              this.createDictText(props.row.status, '5569')
            }</span>;}
        },
        {title: '审核意见', dataIndex: 'opinion',sorter: true}
      ];
    },
    saveDialog(isEscalation) {
      this.visibleForm =true;
      this.isEscalation = isEscalation;
    },
    closeDialog() {
      this.$emit('close');
    },
    async toExamine(){
      console.log("23wa",this.isEscalation)
      if(this.form2.find(x=>x.fieldName ==='checkOpinion').initialValue===''&&this.isEscalation){
        this.$notify.error({title: '提示信息',message:'驳回时要写审核意见!'});
      }else{
        let [err,data] = await this.$refs.infoChanges2.GET_FORM_DATA();
        data = Object.assign({},this.row,data,{escalation:this.isEscalation});
        let res = await examineMileagechange(data);
        if (res.resultCode == 200) {
          this.$notify.success({title: '提示信息',message:'提交成功!'});
          this.$emit('close',{type:'refresh'});
        }
      }
    },
    closeDialog2() {
      this.visibleForm =false;
    },
    cellChange(val, colVal) {
    }
  }
};
</script>

<style scoped>

</style>
